package ro.pub.cs.stadium.document.logic;

import java.util.ArrayList;

public class VariableList {
	ArrayList<Variable> variabile;
	public VariableList() {
		variabile = new ArrayList<Variable>();
	}
	
	public VariableList(ArrayList<Variable> L) {
		variabile = L;
	}
	
	public ArrayList<Variable> getVariables() {
		return variabile;
	}
	
	public void addVariable(Variable V) throws VariableListException {
		Variable in = find(V.getName());
		if (in == null) variabile.add(V); 
		//else throw new VariableListException("duplicate variable:"+in.getName());
		
	}
	
	public Variable find(String name) {
		for (Variable i : variabile) if (i.getName().equals(name)) return i;
		return null;
	}
	
	public void merge(VariableList V) {
		for (Variable v : V.getVariables()) {
			addVariable(v);
		}
	}
	
	public String toString() {
		return variabile.toString();
	}
	
	public void remove(Variable V) {
		variabile.remove(V);
	}
}

class VariableListException extends RuntimeException {
	public VariableListException(String text) {
		super(text);
	}
}